//
//  SubscribeUserCell.swift
//  NDAi
//
//  Created by 丸子 on 2024/7/4.
//

import UIKit

class SubscribeUserCell: UITableViewCell {
    lazy var logoIV: UIImageView = {
      let imageView = UIImageView()
       imageView.image = UIImage(named: "icon_vip_alipay")
       imageView.contentMode = .scaleToFill
       imageView.clipsToBounds = true
        imageView.allRound(25)
       return imageView
   }()
   
    lazy var phoneLb: UILabel = {
      let label = UILabel()
       label.text = ""
       label.textColor = .white
       label.font = UIFont.pingFangSCMedium(ofSize: 16)
       return label
   }()
    
    lazy var vip: UILabel = {
      let label = UILabel()
       label.text = ""
       label.textColor = UIColor(hexString: "#FFB056")
       label.font = UIFont.pingFangSCMedium(ofSize: 12)
       return label
   }()
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        selectionStyle = .none
        backgroundColor = .clear
        self.contentView.corners([.layerMinXMinYCorner, .layerMaxXMinYCorner], cornerRadius: 8)
        self.contentView.addSubviews([logoIV, phoneLb, vip])
        logoIV.snp.makeConstraints { make in
            make.width.equalTo(logoIV.snp.height)
            make.height.equalTo(50)
            make.leading.equalToSuperview().offset(16)
            make.top.bottom.equalToSuperview().inset(12)
        }
        
        phoneLb.snp.makeConstraints { make in
            make.top.equalTo(logoIV.snp.top).offset(4)
            make.leading.equalTo(logoIV.snp.trailing).offset(10)
        }
        
        vip.snp.makeConstraints { make in
            make.top.equalTo(phoneLb.snp.bottom).offset(2)
            make.leading.equalTo(logoIV.snp.trailing).offset(10)
        }
        
    }
    
    func setup(){
        logoIV.sd_setImage(with: URL(string: Appearance.shared.accoutModel?.userOtherInfo?.icon ?? ""))
        phoneLb.text = Appearance.shared.accoutModel?.userOtherInfo?.nickname ?? "你的 AI 会员"
        if let end = Appearance.shared.accoutModel?.userOtherInfo?.vip_end_time?.checkVIPExpiryDate(), !end {
            vip.text = "终身会员"
        }else {
            if let end = Appearance.shared.accoutModel?.userOtherInfo?.vip_end_time?.vipExpirationTime() {
                vip.text = "到期时间: \(end)"
            }else {
                vip.text = "非会员"
            }
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}
